/*
 * StopAction.java
 *
 * Created on June 22, 2005, 7:33 PM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */
package com.bff.mpd.musicjukebox.lib.actions;

import com.bff.mpd.utils.Utils;
import java.awt.event.ActionEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;
import org.bff.javampd.MPDPlayer;
import org.bff.javampd.exception.MPDConnectionException;
import org.bff.javampd.exception.MPDPlayerException;

/**
 *
 * @author Bill
 */
public class StopAction extends AbstractAction {

    private MPDPlayer player;

    /** Creates a new instance of StopAction */
    public StopAction(MPDPlayer player) {
        super(Utils.getMessage("ACTION_STOP_NAME"));
        this.player = player;

        putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("/resources/mpd/player_stop.png")));
        putValue(Action.MNEMONIC_KEY, new Integer('S'));
        putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl S"));
        putValue(Action.SHORT_DESCRIPTION, Utils.getMessage("ACTION_STOP_SHORT_DESC"));
    }

    @Override
    public void actionPerformed(ActionEvent evt) {
        try {
            player.stop();
        } catch (MPDConnectionException ex) {
            Logger.getLogger(StopAction.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MPDPlayerException ex) {
            Logger.getLogger(StopAction.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
